package com.headwind.mq.activemq.controller;

import com.headwind.entity.HwMood;
import com.headwind.mq.Constance;
import com.headwind.mq.activemq.producer.HwMoodProducer;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Destination;
import java.util.Date;

/**
 * @author : Headwind
 * @version : 1.0
 * @date : Created in 2020/8/10
 * @description : 访问控制类
 */
@RestController
public class HwMoodController {
    private final HwMoodProducer hwMoodProducer;

    @Autowired
    public HwMoodController(HwMoodProducer hwMoodProducer) {
        this.hwMoodProducer = hwMoodProducer;
    }

    @GetMapping("/send")
    public void sendMessage() {
        Destination destination = new ActiveMQQueue(Constance.HW_QUEUE);
        hwMoodProducer.sendMessage(destination, "Hello,ActiveMQ！");
    }

    @GetMapping("/async-send")
    public String asyncSendMessage(){
        Destination destination = new ActiveMQQueue(Constance.HW_QUEUE_ASYNC_SAVE);
        HwMood hwMood = new HwMood();
        hwMood.setId("123");
        hwMood.setContent("你好，有新商品上线了！");
        hwMood.setUserId("John123");
        hwMood.setPraiseNum(12);
        hwMood.setPublishTime(new Date());
        hwMoodProducer.sendMessage(destination,hwMood);
        return "发表成功！";
    }
}
